package leetcode.code1021;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public String removeOuterParentheses(String s) {
		char[] cs = s.toCharArray();
		int len = cs.length, p = 0, l = -1;
		char[] ans = new char[len];
		for (int i = 0; i < ans.length; i++) {
			char c = cs[i];
			if (c == '(') {
				l++;
				if (l > 0) {
					ans[p++] = c;
				}
			} else {
				l--;
				if (l >= 0) {
					ans[p++] = c;
				}
			}

		}
		return new String(ans, 0, p);
	}

	@Override
	public void debug4() {
		H.compare("()()()", this.removeOuterParentheses("(()())(())"));
		H.compare("()()()()(())", this.removeOuterParentheses("(()())(())(()(()))"));
		H.compare("", this.removeOuterParentheses("()()"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
